import { MockMethod } from 'vite-plugin-mock';
import { resultSuccess, resultError } from './_util';

const userInfo = {
  userId: '1',
  username: 'admin',
  realName: '管理员',
  avatar: 'https://q1.qlogo.cn/g?b=qq&nk=190848757&s=640',
  desc: '管理员',
  password: '123456',
  token: 'fakeToken1',
  roles: [
    {
      roleName: 'Super Admin',
      value: 'super',
    },
  ],
};

export default [
  {
    url: '/api/login',
    timeout: 200,
    method: 'post',
    response: ({ body }) => {
      const { username, password } = body;
      if (username === 'admin' && password === '123456') {
        return resultSuccess({
          token: 'fakeToken1',
        });
      } else {
        return resultError('账号或密码错误！');
      }
    },
  },
  {
    url: '/api/getUserInfo',
    method: 'get',
    response: (request) => {
      return resultSuccess(userInfo);
    },
  },
  {
    url: '/api/logout',
    timeout: 200,
    method: 'get',
    response: (request) => {
      return resultSuccess(null);
    },
  },
] as MockMethod[]; 